<template>
    <tr>
        <td><input type="checkbox" :checked="item.checked" @click="inputFn(index)"></td>
        <td>{{ item.name}}</td>
        <td>{{ item.price}}</td>
        <td>
            <button @click="btnClickFn(-1,index)">-</button>
            <span>{{ item.num}}</span>
             <button @click="btnClickFn(1,index)">+</button>
        </td>
        <td>{{ item.price*item.num}}</td>
        <td><button @click="delFn(index)">删除</button></td>
    </tr>
</template>

<script>
export default {
  props: ['item', 'index'],
  methods: {
    btnClickFn (count, index) {
      // console.log(count, index)
      const newNum = this.item.num + count
      if (newNum < 1) return
      this.$store.commit('mycart/amendNum', { num: newNum, index })
    },
    inputFn (index) {
      this.$store.commit('mycart/inputChange', index)
    },
    delFn (index) {
      // console.log(index);
      this.$store.commit('mycart/delbutton', index)
    }
  }
}
</script>

<style>

</style>
